package edu.action;



import java.util.List;

import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;

import edu.model.Form;
import edu.service.FormService;



public class FormAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = -2116833997089520571L;
	
	private int	formId = 0;

	private Form form = null;
	private List<Form> formList = null;
	
	private FormService formService = null;
	
	
	public int getFormId() {
		return formId;
	}
	public void setFormId(int formId) {
		this.formId = formId;
	}
	public Form getForm() {
		return form;
	}
	public void setForm(Form form) {
		this.form = form;
	}
	public List<Form> getFormList() {
		return formList;
	}
	public void setFormList(List<Form> formList) {
		this.formList = formList;
	}
	public FormService getFormService() {
		return formService;
	}
	public void setFormService(FormService formService) {
		this.formService = formService;
	}
	
	
	public String detail(){
		form = formService.getFormById(formId);
		
		if(form != null){
			System.out.println(form.getFormName());
			return form.getFormPath();
		}
		return ERROR;
	}
	
	public String list(){
		formList = formService.getAllForm();
		ServletActionContext.getRequest().setAttribute("formList", formList);
		return SUCCESS;
	}
	
	public String show(){
		form = formService.getFormById(formId);
		if(form != null) {
			return SUCCESS;
		}
		return ERROR;
	}
}
